﻿<?php 
function all_trim($str){
	return preg_replace('/\s+/','',$str);
	// return preg_replace('/[ ]/','',$str);
}
$str='aa  哈 市  1';
// echo all_trim($str);

function preg_replace_arr(array $patterns,array $replacements,$str){
	return preg_replace($patterns,$replacements,$str);
}

$patterns=['/aa/','/\s/'];
$replacements=['nn','--'];
// echo preg_replace_arr($patterns,$replacements,$str);   //nn----哈--市
$patterns=['/aa/','/\s/','/\d/'];
$replacements=['nn','--','6666'];
echo preg_replace_arr($patterns,$replacements,$str);   //nn----哈--市----6666